package com.jackson.passjava.member.controller;

import com.jackson.passjava.common.utils.R;
import com.jackson.passjava.member.config.MemberConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @application:
 * @author: LiYuhang
 * @Date: 2021/8/17 21:49
 * @version: 0.1
 * @Description :
 */
@RestController
@Slf4j
@RequestMapping("/test/config")
public class ConfigTestController {

    final   MemberConstant memberConstant;
    public ConfigTestController(MemberConstant memberConstant) {
        this.memberConstant = memberConstant;
    }

    @Value("${nacos.config.member.nickname:liyuhang}")
    private String nickname;

    @Value("${nacos.config.member.age:18}")
    private Integer age;

    /**
     * 获取本地配置
     * @return
     */
    @RequestMapping(value = "/my-config")
    public R localConfig(){
        return R.ok().put("nickname",memberConstant.getNickname()).put("age",memberConstant.getAge());
    }

    /**
     * 获取本地 & nacos 配置
     * @return
     */
    @RequestMapping(value = "/nacos-config")
    public R nacosConfig(){
        return R.ok().put("nickname",nickname).put("age",age);
    }
}
